#include "StdAfx.h"
#include "XeAxWindow.h"

HRESULT STDMETHODCALLTYPE CXeAxWindow::QueryInterface(
	REFIID riid,
	void **ppvObject
	)
{
	ATLASSERT(NULL != ppvObject);
	if (NULL == ppvObject)
	{
		return E_POINTER;
	}

	*ppvObject = NULL;
	if (InlineIsEqualGUID(IID_IOleCommandTarget, riid))
	{
		*ppvObject = static_cast<IOleCommandTarget*>(this);
		AddRef();
		return S_OK;
	}
	else
	{
		return _Super::QueryInterface(riid, ppvObject);
	}
}

STDMETHODIMP CXeAxWindow::QueryService(
	REFGUID rsid,
	REFIID riid,
	void **ppvObj
	)
{
	ATLASSERT(NULL != ppvObj);
	if (NULL == ppvObj)
	{
		return E_POINTER;
	}

	*ppvObj = NULL;
	return __super::QueryService(rsid, riid, ppvObj);
}

ULONG STDMETHODCALLTYPE CXeAxWindow::AddRef()
{
	return _Super::AddRef();
}

ULONG STDMETHODCALLTYPE CXeAxWindow::Release()
{
	return _Super::Release();
}

////////////////////////////////////////////////////////////////////////////
HRESULT STDMETHODCALLTYPE CXeAxWindow::QueryStatus( 
	/* [unique][in] */ const GUID *pguidCmdGroup,
	/* [in] */ ULONG uCmds,
	/* [out][in][size_is] */ OLECMD prgCmds[],
	/* [unique][out][in] */ OLECMDTEXT *pCmdText
	)
{
	return S_OK;
}

HRESULT STDMETHODCALLTYPE CXeAxWindow::Exec( 
	/* [unique][in] */ const GUID *pguidCmdGroup,
	/* [in] */ DWORD dwCmdID,
	/* [in] */ DWORD dwCmdexecopt,
	/* [unique][in] */ VARIANT *pvaIn,
	/* [unique][out][in] */ VARIANT *pvaOut
	)
{
	if ((NULL != pguidCmdGroup) && InlineIsEqualGUID(*pguidCmdGroup, CGID_DocHostCommandHandler))
	{
		switch(dwCmdID)
		{
		case OLECMDID_SHOWSCRIPTERROR:
			{
				// see http://support.microsoft.com/kb/261003 for more info
				(*pvaOut).vt = VT_BOOL;
				(*pvaOut).boolVal = VARIANT_TRUE;
				return S_OK;
			}
		default:
			break;
		}
	}

	return OLECMDERR_E_NOTSUPPORTED;
}